<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
    .router-link-active{
        color:lightgreen;
    }
    .router-link-exact-active{
        color:green;
    }
    </style>
  </head>
  <body>
    <div id="app">
      <ul>
        <li><router-link to="/">Home</router-link></li>
        <li><router-link to="/user">User</router-link></li>
        <li><router-link to="/profile">Profile</router-link></li>
      </ul>
      <router-view></router-view>
    </div>
    <script src="vue.js"></script>
    <script src="my-vue-router.js"></script>
    <script>
      //定义了三个将要用来匹配并渲染的路由组件
      const Home = { template: "<div>Home</div>" };
      const User = { template: "<div>User</div>" };
      const Profile = { template: "<div>Profile</div>" };
      //定义了路由的配置，每个路由配置包含了一个路径path和一个对应的组件
      //当用户导航到一个路径的时候，会渲染对应的组件到router-view
      const routes = [
        { path: "/", component: Home },
        { path: "/user", component: User },
        { path: "/profile", component: Profile },
      ];
      //创建VueRouter的实例，传入路由配置
      var router = new VueRouter({
        routes
      });
      //创建和挂载Vue实例
      var vm = new Vue({
        el: "#app",
        router
      });
    </script>
  </body>
</html>
